package com.a01_2021.thousandstimes.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * @Author E1xP@foxmail.com
 * @Version 1.0
 * @PACKAGE_NAME com.a01_2021.thousandstimes.config
 * @CLASS_NAME MvcConfig
 * @Description TODO MVC设置类
 * @Date 2021/3/20 上午 8:34
 **/
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Value("${path.basePath}")
    String basePath;

    @Value("${path.reportAttachmentFolder}")
    String reportFolder;//报告附件存储文件夹

    @Value("${path.userHeadPicFolder}")
    String headPicFolder;//头像文件存储文件夹

    @Value("${path.interpolateAttachmentFolder}")
    String interpolateFolder;//内推附件存储文件夹

    @Value("${path.personnelInformationFolder}")
    String personnelInformationFolder;//简历存储文件夹

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //映射简历文件地址
        registry.addResourceHandler("/resume/**").addResourceLocations("file:" + (basePath.endsWith("/") || basePath.endsWith("\\") || personnelInformationFolder.startsWith("/") ? basePath + personnelInformationFolder + "/" : basePath + "/" + personnelInformationFolder + "/"));
        //映射内推附件地址
        registry.addResourceHandler("/interpolate/**").addResourceLocations("file:" + (basePath.endsWith("/") || basePath.endsWith("\\") || interpolateFolder.startsWith("/") ? basePath + interpolateFolder + "/" : basePath + "/" + interpolateFolder + "/"));
        //映射报告附件文件地址
        registry.addResourceHandler("/report/**").addResourceLocations("file:" + (basePath.endsWith("/") || basePath.endsWith("\\") || reportFolder.startsWith("/") ? basePath + reportFolder + "/" : basePath + "/" + reportFolder + "/"));
        //映射头像文件地址
        registry.addResourceHandler("/headPic/**").addResourceLocations("file:" + (basePath.endsWith("/") || basePath.endsWith("\\") || headPicFolder.startsWith("/") ? basePath + headPicFolder + "/" : basePath + "/" + headPicFolder + "/"));
    }

}
